import Vue from "vue"
import VueRouter from "vue-router"
// import store from '@/store';

Vue.use(VueRouter)

const routes = [
      {
        path: '/',         // 根路径
        redirect: '/home/welcome'
      },
      {
        path: '/login',
        name: 'Login',
        component: () => import('../login.vue')
      },
      {
        path: '/home',         // home菜单
        redirect: '/home/welcome',
        component: () =>import('../index.vue'),
        children: [
          {
            path: 'welcome',
            name: 'Welcome',
            component: () => import('../components/home/welcome.vue'),
          },
          {
            path:'dashboard',
            name:'Dashboard',
            component: () => import('../components/home/dashboard.vue'),
          }
        ]
      },
      {
        path:'/rights',
        component: () => import('../index.vue'),
        children:[
          {
            path:'users',
            name:'UsersManage',
            component: () => import('../components/rights/users-manage.vue'),
          },
          {
            path:'roles',
            name:'RolesManage',
            component: () => import('../components/rights/roles-manage.vue'),
          },
          {
            path:'permissions',
            name:'PermissionsManage',
            component: () => import('../components/rights/permissions-manage.vue'),
          }
        ]
      }
]

const router = new VueRouter({
    mode: 'history',
    routes
})

//除了login页，跳转任何页面之前都要检查下token是否存在，如果不存在直接跳login

// router.beforeEach((to,from,next) => {
//     if(to.path !== '/login' && !store.state.token && from.path !== '/login'){
//         next('/login');
//     }else{
//         next();
//     }
    
// })

export default router